package com.itgaohe.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itgaohe.dao.entity.Like;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface LikeMapper extends BaseMapper<Like> {
    @Select("SELECT * FROM tb_like WHERE user_id = #{userId} AND blog_id = #{blogId}")
    List<Like> getIsLike(@Param("blogId") Long blogId, @Param("userId") Long userId);

    @Insert("INSERT INTO tb_like(user_id, blog_id, create_time) VALUES (#{userId}, #{blogId}, #{createTime})")
    int insertLike(
                   @Param("userId") Long userId,
                   @Param("blogId") Long blogId,
                   @Param("createTime") LocalDateTime createTime);
    @Select("select count(*) from tb_like")
    int countLike(@Param("blogId") Long blogId);

}
